<template>
  <div class="app-container">
    <div class="head-container">
      <el-input v-model="query.value" clearable placeholder="全表模糊搜索" maxlength="10" style="width: 200px;"
                class="filter-item" @keyup.enter.native="toQuery"/>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
    </div>
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;" border>
      <el-table-column prop="username" label="登录账号"/>
      <el-table-column prop="ip" label="锁定IP"/>
      <el-table-column prop="failCount" label="失败次数峰值"/>
      <el-table-column prop="expiration" label="剩余解锁时间"/>
      <el-table-column prop="createTime" label="操作" width="100px" fixed="right">
        <template slot-scope="scope">
          <el-popover
            v-permission="['ADMIN','LOCK_ALL','LOCK_DELETE']"
            :ref="scope.$index"
            placement="top"
            width="180">
            <p>确定解锁该用户吗？</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.$index].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.$index, scope.row)">
                确定
              </el-button>
            </div>
            <el-button v-permission="['ADMIN','LOCK_ALL','LOCK_DELETE']" slot="reference" size="mini" type="text">解锁
            </el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"/>
  </div>
</template>

<script>
  import initData from '@/mixins/initData'
  import { del } from '@/api/framework/system/lockUser'

  export default {
    name: 'lockUser',
    mixins: [initData],
    data() {
      return {
        delLoading: false,
        downloadLoading: false
      }
    },
    created() {
      this.$nextTick(() => {
        this.init()
      })
    },
    methods: {
      beforeInit() {
        this.url = 'auth/lockUserAll'
        this.params = { page: this.page, size: this.size }
        if (this.query.value) {
          this.params['filter'] = this.query.value
        }
        return true
      },
      subDelete(index, data) {
        this.delLoading = true
        del(data).then(res => {
          this.delLoading = false
          this.$refs[index].doClose()
          this.dleChangePage()
          this.init()
          this.$notify({
            title: '解锁成功',
            type: 'success',
            duration: 2500
          })
        }).catch(err => {
          this.delLoading = false
          this.$refs[index].doClose()
        })
      }
    }
  }
</script>
